package org.dkakunsi.aplikasitoko.form;

import javax.swing.JButton;
import javax.swing.JInternalFrame;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.table.DefaultTableModel;

import org.dkakunsi.aplikasitoko.service.DataService;

import java.awt.event.ActionListener;

public abstract class MyForm extends JInternalFrame implements ActionListener {

	private static final long serialVersionUID = 1L;
	
	private JButton btnExit;
	protected JTable table;
	protected JScrollPane scrollPane;
	protected DefaultTableModel tabModel;
	protected DataService ds;
	protected Desktop parentForm;

	/**
	 * Create the frame, with desktop not initialized
	 */
	public MyForm(String judul) {
		super(judul);
		setter();
	}
	
	/**
	 * Create the frame, with desktop initialized
	 */
	public MyForm(String judul, Desktop desktop) {
		super(judul);
		this.parentForm = desktop;
		setter();
	}
	
	private void setter(){
		setBounds(10, 10, 1000, 290);
		getContentPane().setLayout(null);

		scrollPane = new JScrollPane();
		scrollPane.setBounds(12, 12, 629, 173);
		getContentPane().add(scrollPane);

        table = new JTable(){
			private static final long serialVersionUID = 1L;

			@Override
            public boolean isCellEditable(int rowIndex, int colIndex) {
                return false;
            }
        };
		scrollPane.setViewportView(table);

		btnExit = new JButton("EXIT");
		btnExit.setBounds(790, 210, 100, 25);
		getContentPane().add(btnExit);
		btnExit.setActionCommand("EXIT");
		btnExit.addActionListener(this);
	}
	
	protected void setUkuran(int width, int height){
		setBounds(10, 10, width, height);
	}
	
	protected void setBtnExit(int x, int y){
		btnExit.setBounds(x, y, 100, 25);
	}
	
	protected void setUnableTable(){
		scrollPane.setVisible(false);
	}
	
	protected void setUkuranTable(int width, int height){
		scrollPane.setBounds(12, 12, width, height);
	}

	protected void setUkuranTable(int x, int y, int width, int height){
		scrollPane.setBounds(x, y, width, height);
	}

	protected void setTableModel(String[] kolom){
        tabModel = new DefaultTableModel(null,kolom);
        table.setModel(tabModel);
	}
	
	protected void exit(){
		this.dispose();
	}
	
	protected Desktop getParentForm(){
		return this.parentForm;
	}
	
	protected abstract void loadView();
	protected abstract void loadInitialize();
}
